package mysql

import (
	"gorm.io/gorm"
	"home-mgr-sys/homerpc/homerpc"
)

type Home struct {
	gorm.Model
	Title   string  `gorm:"type:varchar(30);not null;comment:标题"`
	Address string  `gorm:"type:varchar(30);not null;comment:地址"`
	Price   float64 `gorm:"type:decimal(10);not null;comment:价格"`
}

func (h *Home) HomeShow(db *gorm.DB, id int64) error {
	return db.Where("id=?", id).First(&h).Error
}

func (h *Home) HomeList(db *gorm.DB, in *homerpc.HomeListRequest, list []*homerpc.HomeList) ([]*homerpc.HomeList, error) {
	err2 := db.Model(&h).
		Select("homes.id as homes_id",
			"homes.address",
			"homes.price").
		Scopes(Paginate(int(in.Page), int(in.Size))).Find(&list).Error
	return list, err2
}
